const Mock = require('mockjs')

// 模拟用户数据
const adminUser = {
  id: 1,
  username: 'admin',
  nickname: '管理员',
  avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
  roles: ['admin'],
  permissions: ['*:*:*']
}

// 模拟token
const token = 'admin-token'

module.exports = [
  // 登录
  {
    url: '/auth/login',
    method: 'post',
    response: ({ body }) => {
      const { username, password } = body
      
      // 简单验证，实际项目中应该有更复杂的验证逻辑
      if (username === 'admin' && password === 'admin123') {
        return {
          code: 200,
          msg: '登录成功',
          data: {
            token
          }
        }
      } else {
        return {
          code: 401,
          msg: '用户名或密码错误'
        }
      }
    }
  },
  
  // 获取用户信息
  {
    url: '/user/info',
    method: 'get',
    response: ({ headers }) => {
      // 检查是否有token
      const authorization = headers.authorization || ''
      if (!authorization.includes(token)) {
        return {
          code: 401,
          msg: '未授权，请登录'
        }
      }
      
      return {
        code: 200,
        msg: '操作成功',
        data: adminUser
      }
    }
  },
  
  // 登出
  {
    url: '/auth/logout',
    method: 'post',
    response: () => {
      return {
        code: 200,
        msg: '退出成功'
      }
    }
  }
]
